package com.shangcheng.server.controller;

import com.shangcheng.model.domain.SmsHomeRecommendProduct;
import com.shangcheng.model.vo.PageResult;
import com.shangcheng.model.vo.result.Result;
import com.shangcheng.server.service.SmsHomeRecommendProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shiqiang
 * @version 1.0
 * @date 2022/5/13 11:30
 */
@RestController
@RequestMapping("/home/recommendProduct")
public class SmsHomeRecommendProductController {
    @Autowired
    private SmsHomeRecommendProductService homeRecommendProductService;

    /**
     * 批量添加首页推荐
     * @param homeRecommendProductList 新品集合
     * @return
     */
    @PostMapping("/create")
    public ResponseEntity createNewPro(@RequestBody List<SmsHomeRecommendProduct> homeRecommendProductList){
        homeRecommendProductService.createRecPro(homeRecommendProductList);
        return ResponseEntity.ok(new Result(200,null,"添加成功"));
    }

    /**
     * 批量删除推荐
     * @param ids 新品ids
     * @return
     */
    @PostMapping("/delete")
    public ResponseEntity deleteNewPro(Integer[] ids){
        homeRecommendProductService.deleteRecPro(ids);
        return ResponseEntity.ok(new Result(200,null,"删除成功"));
    }

    /**
     * 分页查询推荐
     * @param pageNum
     * @param pageSize
     * @param productName
     * @param recommendStatus
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity RecProList(@RequestParam(defaultValue = "1") Integer pageNum,
                                     @RequestParam(defaultValue = "10") Integer pageSize,String productName,Integer recommendStatus){
        PageResult result=homeRecommendProductService.RecProList(pageNum,pageSize,productName,recommendStatus);
        return ResponseEntity.ok(new Result(200,result,null));
    }

    /**
     * 批量修改推荐状态
     * @param ids
     * @param recommendStatus
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public ResponseEntity updateRecommendStatus(Integer[] ids,Integer recommendStatus){
        homeRecommendProductService.updateRecommendStatus(ids,recommendStatus);
        return ResponseEntity.ok(new Result(200,null,"修改成功"));
    }

    /**
     * 修改推荐排序
     * @param id
     * @param sort
     * @return
     */
    @PostMapping("/update/sort/{id}")
    public ResponseEntity updateSort(@PathVariable("id") Integer id,@RequestParam Integer sort){
        homeRecommendProductService.updateRecSort(id,sort);
        return ResponseEntity.ok(new Result(200,null,"修改成功"));
    }
}
